//
//  HYStoreCell.m
//  HaiYue
//
//  Created by skyline on 2018/6/15.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYStoreCell.h"
@interface HYStoreCell()
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYLabel *jifenLBL;
@property (nonatomic, strong) HYView *imgBack;
@property (nonatomic, strong) UIImageView *img;

@end
@implementation HYStoreCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.layer.cornerRadius = 5.0;
        self.layer.borderColor = TEXT_GRAY_COLOR.CGColor;
        self.layer.borderWidth = 0.5;
        self.layer.masksToBounds = YES;
        self.backgroundColor = CELL_LINE_COLOR;
        
        //        self.titleLBL.text = @"彩虹碧玺手链";
        //        self.jifenLBL.text = @"兑换积分:8";
        //        self.img.image = [UIImage imageNamed:@"4"];
    }
    return self;
}
- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[HYLabel  alloc] initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:ContentFont]];
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP / 2.0);
            make.top.equalTo(self).with.offset(GAP / 2.0);
        }];
    }
    return _titleLBL;
}

- (HYLabel *)jifenLBL
{
    if (!_jifenLBL)
    {
        _jifenLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont]];
        [self addSubview:_jifenLBL];
        [_jifenLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP / 2.0);
            make.top.equalTo(self.titleLBL.mas_bottom).with.offset(GAP / 2.0);
        }];
    }
    return _jifenLBL;
}

- (HYView *)imgBack
{
    if (!_imgBack)
    {
        _imgBack = [[HYView alloc] initWithColor:[UIColor clearColor]];
        _imgBack.bounds = CGRectMake(0, 0, (SCREEN_WIDTH - GAP * 3.0) / 2.0 - GAP, (SCREEN_WIDTH - GAP * 3.0) / 2.0 - self.titleLBL.bounds.size.height - self.jifenLBL.bounds.size.height - GAP * 2.0);
        [self addSubview:_imgBack];
        [_imgBack mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.jifenLBL.mas_bottom).with.offset(GAP / 2.0);
            make.left.equalTo(self).with.offset(GAP / 2.0);
            make.right.equalTo(self).with.offset(-GAP / 2.0);
            make.bottom.equalTo(self).with.offset(-GAP / 2.0);
        }];
    }
    return _imgBack;
}

- (UIImageView *)img
{
    if (!_img)
    {
        _img = [[UIImageView alloc] init];
        [self.imgBack addSubview:_img];
        [_img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.imgBack);
        }];
    }
    return _img;
}
- (void)setModel:(HYGoodsModel *)model
{
    if (_model != model)
    {
        _model = model;
        self.titleLBL.text = _model.goodsname;
        self.jifenLBL.text = [NSString stringWithFormat:@"兑换积分:%@",_model.vipscore];
        [self.img setImageWithURL:[NSURL URLWithString:_model.pic] placeholderImage:nil];
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.backgroundColor = RGBA(230, 230, 230, 0.8);
    [super touchesBegan:touches withEvent:event];
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.backgroundColor = CELL_LINE_COLOR;
        [super touchesEnded:touches withEvent:event];
    });
}

@end
